
package com.gp.adapter;

import java.util.List;

import com.gp.R;
import com.gp.model.MenuItem;
import com.gp.model.SelfGuideListItem;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;


/**
 * @author shijunxing
 * @className MenuGridViewAdapter
 * @date Sep 7, 2013 11:16:31 AM
 * @version 1.0
 * @Description 自定义地图菜单列表的适配器
 */
public class MenuGridViewAdapter extends BaseAdapter {

    // 上下文变量
    private Context mContext;
    // 存放SelfGuideListItem的列表，
    private List<MenuItem> mLists;
    // 布局压泵
    private LayoutInflater mLayoutInflater;

    public MenuGridViewAdapter( Context pContext,
            List<MenuItem> pLists ) {

        this.mContext = pContext;
        this.mLists = pLists;
        mLayoutInflater = LayoutInflater.from(pContext);
    }

    @Override
    public int getCount() {

        return mLists != null ? mLists.size() : 0;
    }

    @Override
    public Object getItem(int arg0) {

        return mLists.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {

        return arg0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        Holder qHolder = null;
        // 重写getView()方法的步骤：
        // 1，将列表项的布局压进来
        if (convertView == null) {

            qHolder = new Holder();
            // 这里传的是你定义列表项的布局id
            convertView = mLayoutInflater.inflate(
                    R.layout.item_menu, null);
            // 2,初始化列表项中的控件
            qHolder.mSight_ima = (ImageView) convertView
                    .findViewById(R.id.item_image);
            qHolder.mSight_name = (TextView) convertView
                    .findViewById(R.id.item_text);

            convertView.setTag(qHolder);
        }
        else {
            qHolder = (Holder) convertView.getTag();
        }

        // 3，绑定数据到控件上
        qHolder.mSight_ima.setImageResource(mLists.get(position).getmImaID());
        qHolder.mSight_name.setText(mLists.get(position).getmName());

        return convertView;
    }

    private static class Holder {
        ImageView mSight_ima;
        TextView mSight_name;

    }

}
